/**
 * 系统平台
 * moonvip_admin
 * com.tz.web.permission
 * PermissionController.java
 * 创建人:小胡
 * 时间：2016年11月19日 17:05:29
 *
 */
package com.tz.web.permission;

import com.tz.auth.AuthPassport;
import com.tz.bean.Permission;
import com.tz.bean.TzParams;
import com.tz.service.permission.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;

/**
 * 权限管理web
 * PermissionController
 * 创建人:小胡
 * 时间：2016年11月19日 17:05:29
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("/admin/permission")
public class PermissionController {
	
	@Autowired
	private IPermissionService permissionService;

	/*列表查询*/
	@AuthPassport
	@RequestMapping("/list")
	public String list(TzParams params){
		return "permission/list";
	}

	/*列表查询*/
	@ResponseBody
	@RequestMapping("/root")
	public HashMap<String,Object> root(TzParams params){
		return permissionService.findPermissions(params);
	}


	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public int delete(Integer id){
		int n = permissionService.delete(id);
		return n;
	}

	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public Permission edit(Integer id) {
		return permissionService.getRecordById(id);
	}


	@AuthPassport
	@RequestMapping(value = "/save",method= RequestMethod.POST)
	public String save(Permission permission){
		permissionService.save(permission);
		return "redirect:list";
	}


	@RequestMapping(value="/update",method= RequestMethod.POST)
	public String update(Permission permission){
		permission.setUpdateTime(new Date());
		permissionService.update(permission);
		return "redirect:list";
	}

}
